package com.seeyon.apps.gkcwplugin.dao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.seeyon.apps.gkcwplugin.po.BankAccounts;
import com.seeyon.apps.gkcwplugin.po.ChailfBankPO;
import com.seeyon.apps.gkcwplugin.po.ChailfPJPO;
import com.seeyon.apps.gkcwplugin.po.ChailfPO;
import com.seeyon.apps.gkcwplugin.po.ChailfSonPO;
import com.seeyon.apps.gkcwplugin.po.ChailfSonVO;
import com.seeyon.apps.gkcwplugin.po.ChailfeiVO;
import com.seeyon.apps.gkcwplugin.po.ContactUnit;
import com.seeyon.apps.gkcwplugin.po.DepartmentPO;
import com.seeyon.apps.gkcwplugin.po.DeptToSubject;
import com.seeyon.apps.gkcwplugin.po.FapiaoKjBankPO;
import com.seeyon.apps.gkcwplugin.po.FapiaoKjPJPO;
import com.seeyon.apps.gkcwplugin.po.FapiaoKjPO;
import com.seeyon.apps.gkcwplugin.po.FapiaoRzPJPO;
import com.seeyon.apps.gkcwplugin.po.FapiaoRzPO;
import com.seeyon.apps.gkcwplugin.po.FapiaoRzSonVO;
import com.seeyon.apps.gkcwplugin.po.FapiaoRzVO;
import com.seeyon.apps.gkcwplugin.po.FinancialDataPO;
import com.seeyon.apps.gkcwplugin.po.FukuanBankPO;
import com.seeyon.apps.gkcwplugin.po.FukuanBankVO;
import com.seeyon.apps.gkcwplugin.po.FukuanPJPO;
import com.seeyon.apps.gkcwplugin.po.FukuanPO;
import com.seeyon.apps.gkcwplugin.po.FukuanSonPO;
import com.seeyon.apps.gkcwplugin.po.FukuanSonVO;
import com.seeyon.apps.gkcwplugin.po.FukuanVO;
import com.seeyon.apps.gkcwplugin.po.HetongBankPO;
import com.seeyon.apps.gkcwplugin.po.HetongPJPO;
import com.seeyon.apps.gkcwplugin.po.HetongPO;
import com.seeyon.apps.gkcwplugin.po.HetongSonPO;
import com.seeyon.apps.gkcwplugin.po.HuiKuanBankPO;
import com.seeyon.apps.gkcwplugin.po.HuiKuanPJPO;
import com.seeyon.apps.gkcwplugin.po.HuiKuanPO;
import com.seeyon.apps.gkcwplugin.po.HuiKuanSonPO;
import com.seeyon.apps.gkcwplugin.po.LaowufeiVO;
import com.seeyon.apps.gkcwplugin.po.NeibuZjBankPO;
import com.seeyon.apps.gkcwplugin.po.NeibuZjNbSonVO;
import com.seeyon.apps.gkcwplugin.po.NeibuZjNbVO;
import com.seeyon.apps.gkcwplugin.po.NeibuZjPJPO;
import com.seeyon.apps.gkcwplugin.po.NeibuZjPO;
import com.seeyon.apps.gkcwplugin.po.NeibuZjSonPO;
import com.seeyon.apps.gkcwplugin.po.NeibuZjSonVO;
import com.seeyon.apps.gkcwplugin.po.NeibuZjVO;
import com.seeyon.apps.gkcwplugin.po.Personnel;
import com.seeyon.apps.gkcwplugin.po.SubjectPO;
import com.seeyon.apps.gkcwplugin.po.ZiJinRZPO;
import com.seeyon.apps.gkcwplugin.po.ZiJinRZSonPO;
import com.seeyon.ctp.common.po.ctpenumnew.CtpEnumItemPO;
import com.seeyon.ctp.common.po.filemanager.Attachment;
import com.seeyon.ctp.organization.po.OrgPrincipal;
import com.seeyon.ctp.util.DBAgent;
import com.seeyon.ctp.util.JDBCAgent;


public class DealDataDaoImpl implements DealDataDao{

	@Override
	public void saveDeptList(List<DepartmentPO> depList) {
		DBAgent.saveAll(depList);
	}

	@Override
	public void saveSubjectList(List<SubjectPO> subjectList) {
		DBAgent.saveAll(subjectList);
		
	}

	@Override
	public void savePersonnelList(List<Personnel> personnelList) {
		DBAgent.saveAll(personnelList);
	}

	@Override
	public void saveBankAccountsList(List<BankAccounts> bankAccounts) {
		DBAgent.saveAll(bankAccounts);
		
	}

	@Override
	public void saveContactUnitList(List<ContactUnit> contactUnitList) {
		DBAgent.saveAll(contactUnitList);
	}
	
	@Override
	public void updateContactUnitList(List<ContactUnit> contactUnitList) {
		DBAgent.updateAll(contactUnitList);
	}

	@Override
	public FukuanVO findFukuanById(Long id) {
		Map<String, Object> params=new HashMap<String, Object>();
		String sql=" from FukuanVO where ID=:id";
		params.put("id", id);
		List<FukuanVO> list=DBAgent.find(sql,params);
		if (list!=null&&list.size()>0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public List<FukuanSonVO> findFukuanSon(Long formrecordId) {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql=" from FukuanSonVO where formmain_id=:formrecordId";
		params.put("formrecordId", formrecordId);
		List<FukuanSonVO> list=DBAgent.find(sql, params);
		return list;
	}

	@Override
	public LaowufeiVO findLaowufById(Long id) {
		Map<String, Object> params=new HashMap<String, Object>();
		String sql=" from LaowufeiVO where ID=:id";
		params.put("id", id);
		List<LaowufeiVO> list=DBAgent.find(sql, params);
		if (list!=null&&list.size()>0) {
			return list.get(0);	
		}
		return null;
	}

	@Override
	public FapiaoRzVO findFapiaoRzById(Long id) {
		Map<String, Object> params=new HashMap<String, Object>();
		String sql=" from FapiaoRzVO where ID=:id";
		params.put("id", id);
		List<FapiaoRzVO> list=DBAgent.find(sql, params);
		if (list!=null&&list.size()>0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public List<FapiaoRzSonVO> findFapiaoRzSon(Long formrecordId) {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql=" from FapiaoRzSonVO where formmain_id=:formrecordId";
		params.put("formrecordId", formrecordId);
		List<FapiaoRzSonVO> list=DBAgent.find(sql, params);
		return list;
	}

	@Override
	public ChailfeiVO findChailfById(Long id) {
		Map<String, Object> params=new HashMap<String, Object>();
		String sql=" from ChailfeiVO where ID=:id";
		params.put("id", id);
		List<ChailfeiVO> list=DBAgent.find(sql, params);
		if (list!=null&&list.size()>0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public List<ChailfSonVO> findChailfSon(Long formrecordId) {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql=" from ChailfSonVO where formmain_id=:formrecordId";
		params.put("formrecordId", formrecordId);
		List<ChailfSonVO> list=DBAgent.find(sql, params);
		return list;
	}

	@Override
	public NeibuZjVO findNeibuZjById(Long id) {
		Map<String, Object> params=new HashMap<String, Object>();
		String sql=" from NeibuZjVO where ID=:id";
		params.put("id", id);
		List<NeibuZjVO> list=DBAgent.find(sql, params);
		if (list!=null&&list.size()>0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public List<NeibuZjSonVO> findNeibuZjSon(Long formrecordId) {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql=" from NeibuZjSonVO where formmain_id=:formrecordId";
		params.put("formrecordId", formrecordId);
		List<NeibuZjSonVO> list=DBAgent.find(sql, params);
		return list;
	}

	@Override
	public NeibuZjNbVO findNeibuZjNbById(Long id) {
		Map<String, Object> params=new HashMap<String, Object>();
		String sql=" from NeibuZjNbVO where ID=:id";
		params.put("id", id);
		List<NeibuZjNbVO> list=DBAgent.find(sql, params);
		if (list!=null&&list.size()>0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public List<NeibuZjNbSonVO> findNeibuZjNbSon(Long formrecordId) {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql=" from NeibuZjNbSonVO where formmain_id=:formrecordId";
		params.put("formrecordId", formrecordId);
		List<NeibuZjNbSonVO> list=DBAgent.find(sql, params);
		return list;
	}

	@Override
	public List<Attachment> attachmentList(String attReferenceId,boolean flag) {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql="";
		if (flag) {
			sql=" from Attachment where SUB_REFERENCE=:attReferenceId";
			params.put("attReferenceId", attReferenceId);
		}else {
			sql=" from Attachment where att_reference=:attReferenceId";
			params.put("attReferenceId", attReferenceId);
		}
		
		List<Attachment> list=DBAgent.find(sql, params);
		if (list!=null&&list.size()>0) {
			return list;
		}
		return null;
	}

	@Override
	public DepartmentPO findDeptByCode(String deptCode, String unitCode) {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql=" from DepartmentPO where field0004=:unitCode and field0005=:deptCode";
		params.put("unitCode", unitCode);
		params.put("deptCode", deptCode);
		List<DepartmentPO> list=DBAgent.find(sql, params);
		if (list!=null&&list.size()>0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public ContactUnit findUnitByCode(String unitCode) {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql=" from ContactUnit where field0002=:unitCode and field0032=0";
		params.put("unitCode", unitCode);
		List<ContactUnit> list=DBAgent.find(sql, params);
		if (list!=null&&list.size()>0) {
			return list.get(0);
		}
		return null;
		
	}

	@Override
	public void saveFinancialData(FinancialDataPO po) {
		DBAgent.save(po);
	}

	@Override
	public void updateFinancialData(FinancialDataPO po) {
		DBAgent.update(po);
		
	}

	@Override
	public CtpEnumItemPO getEnum(String id) {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql=" from CtpEnumItemPO where ID=:id";
		params.put("id", id);
		List<CtpEnumItemPO> list=DBAgent.find(sql, params);
		if (list!=null&&list.size()>0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public boolean saveFinancial(FinancialDataPO po) {
		String sql="insert into plugin_financialdata (id,templatecode,formrecordid,summaryid,state,createtime,updatetime,number)"
				+ "values(?,?,?,?,?,?,?,1)";
		List<Object> params=new ArrayList<Object>();
		params.add(po.getId());
		params.add(po.getTemplateCode());
		params.add(po.getFormRecordId());
		params.add(po.getSummaryId());
		params.add(po.getState());
		params.add(po.getCreateTime());
		params.add(po.getUpdateTime());
		int res=0;
		JDBCAgent jdbc=new JDBCAgent();
		try {
			jdbc.batch1Prepare(sql);
			jdbc.batch2Add(params);
			res=jdbc.batch3Execute();
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (res!=0) {
			return true;
		}else {
			return false;
		}
	}

	@Override
	public List<FinancialDataPO> selectFinancial() {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql=" from FinancialDataPO where state=1 and number!=2";
		List<FinancialDataPO> list=DBAgent.find(sql);
		if (list!=null&&list.size()>0) {
			return list;
		}
		return null;
	}

	@Override
	public int updateFinancial(long id,String state,int num) {
		String sql="update plugin_financialdata set state=?,number=? where id=?";
		List<Object> params=new ArrayList<Object>();
		params.add(state);
		params.add(num);
		params.add(id);
		int res=0;
		JDBCAgent jdbc=new JDBCAgent();
		try {
			jdbc.batch1Prepare(sql);
			jdbc.batch2Add(params);
			res=jdbc.batch3Execute();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return res;
	}

	@Override
	public ContactUnit findContactUnitByNm(String LSWLDW_LSWLDWID) {
		Map<String, Object> params=new HashMap<String, Object>();
		String sql=" from ContactUnit where field0001=:LSWLDW_LSWLDWID";
		params.put("LSWLDW_LSWLDWID", LSWLDW_LSWLDWID);
		List<ContactUnit> list=DBAgent.find(sql, params);
		if (list!=null&&list.size()>0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public DepartmentPO findDeptById(String LSBMZD_ID) {
		Map<String, Object> params=new HashMap<String, Object>();
		String sql=" from DepartmentPO where field0003=:LSBMZD_ID";
		params.put("LSBMZD_ID", LSBMZD_ID);
		List<DepartmentPO> list=DBAgent.find(sql, params);
		if (list!=null&&list.size()>0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public void updateDeptList(List<DepartmentPO> deptList) {
		DBAgent.updateAll(deptList);
	}

	@Override
	public void updatePersonList(List<Personnel> personnelList) {
		DBAgent.updateAll(personnelList);
		
	}

	@Override
	public Personnel findPersonById(String LSZGZD_ID) {
		Map<String, Object> params=new HashMap<String, Object>();
		String sql=" from Personnel where field0001=:LSZGZD_ID";
		params.put("LSZGZD_ID", LSZGZD_ID);
		List<Personnel> list=DBAgent.find(sql, params);
		if (list!=null&&list.size()>0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public void updateBankAccountList(List<BankAccounts> bankAccounts) {
		DBAgent.updateAll(bankAccounts);
	}

	@Override
	public BankAccounts findBankAccountsByNm(String BANKACCOUNTID) {
		Map<String, Object> params=new HashMap<String, Object>();
		String sql=" from BankAccounts where field0001=:BANKACCOUNTID";
		params.put("BANKACCOUNTID", BANKACCOUNTID);
		List<BankAccounts> list=DBAgent.find(sql, params);
		if (list!=null&&list.size()>0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public void updateSubjectList(List<SubjectPO> subjectList) {
		DBAgent.updateAll(subjectList);
	}

	@Override
	public SubjectPO findSubjectById(String ZWKMZD_ID) {
		Map<String, Object> params=new HashMap<String, Object>();
		String sql=" from SubjectPO where field0001=:ZWKMZD_ID";
		params.put("ZWKMZD_ID", ZWKMZD_ID);
		List<SubjectPO> list=DBAgent.find(sql, params);
		if (list!=null&&list.size()>0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public List<SubjectPO> findSubjectByBh(String KMBH) {
		
		Map<String, Object> params=new HashMap<String, Object>();
		String sql=" from SubjectPO where field0002 like:KMBH";
		params.put("KMBH", KMBH+"%");
		System.out.println("sql;"+sql);
		List<SubjectPO> list=DBAgent.find(sql, params);
		if (list!=null&&list.size()>0) {
			return list;
		}
		return null;
	}

	@Override
	public void saveDeptSubject(List<DeptToSubject> deptToSubjectList) {
		DBAgent.saveAll(deptToSubjectList);
		
	}

	@Override
	public SubjectPO findSubjectPo(String KMBH) {
		Map<String, Object> params=new HashMap<String, Object>();
		String sql=" from SubjectPO where field0002=:KMBH";
		params.put("KMBH", KMBH);
		System.out.println("sql;"+sql);
		List<SubjectPO> list=DBAgent.find(sql, params);
		if (list!=null&&list.size()>0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public List<DeptToSubject> findDeptSubjectList(String kmnm) {
		Map<String, Object> params=new HashMap<String, Object>();
		String sql=" from DeptToSubject where field0001=:kmnm";
		params.put("kmnm", kmnm);
		List<DeptToSubject> list=DBAgent.find(sql, params);
		if (list!=null&&list.size()>0) {
			return list;
		}
		return null;
	}

	@Override
	public void updateDeptSubjectList(List<DeptToSubject> list) {
		DBAgent.updateAll(list);
		
	}

	@Override
	public List<FukuanBankVO> findFukuanBank(Long formrecordId) {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql=" from FukuanBankVO where formmain_id=:formrecordId";
		params.put("formrecordId", formrecordId);
		List<FukuanBankVO> list=DBAgent.find(sql, params);
		return list;
	}

	@Override
	public FukuanPO findFukuanPOById(Long id) {
		Map<String, Object> params=new HashMap<String, Object>();
		String sql=" from FukuanPO where ID=:id";
		params.put("id", id);
		List<FukuanPO> list=DBAgent.find(sql,params);
		if (list!=null&&list.size()>0) {
			return list.get(0);
		}
		return null;
	}
	
	@Override
	public List<FukuanPJPO> findFukuanPJPO(Long formrecordId) {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql=" from FukuanPJPO where formmain_id=:formrecordId";
		params.put("formrecordId", formrecordId);
		List<FukuanPJPO> list=DBAgent.find(sql, params);
		return list;
	}

	@Override
	public List<FukuanSonPO> findFukuanSonPO(Long formrecordId) {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql=" from FukuanSonPO where formmain_id=:formrecordId";
		params.put("formrecordId", formrecordId);
		List<FukuanSonPO> list=DBAgent.find(sql, params);
		return list;
	}

	@Override
	public List<FukuanBankPO> findFukuanBankPO(Long formrecordId) {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql=" from FukuanBankPO where formmain_id=:formrecordId";
		params.put("formrecordId", formrecordId);
		List<FukuanBankPO> list=DBAgent.find(sql, params);
		return list;
	}

	@Override
	public FukuanBankPO findFukuanBankPOById(String pzh) {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql=" from FukuanBankPO where field0197=:pzh";
		params.put("pzh", pzh);
		List<FukuanBankPO> list=DBAgent.find(sql, params);
		if (list!=null&&list.size()>0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public void updateFukuanBankPOData(FukuanBankPO po) {
		DBAgent.saveOrUpdate(po);
	}

	@Override
	public ZiJinRZPO findZiJinRZPOById(Long id) {
		Map<String, Object> params=new HashMap<String, Object>();
		String sql=" from ZiJinRZPO where ID=:id";
		params.put("id", id);
		List<ZiJinRZPO> list=DBAgent.find(sql,params);
		if (list!=null&&list.size()>0) {
			return list.get(0);
		}
		return null;
	}
	
	@Override
	public List<ZiJinRZSonPO> findZiJinRZSonPO(Long formrecordId) {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql=" from ZiJinRZSonPO where formmain_id=:formrecordId";
		params.put("formrecordId", formrecordId);
		List<ZiJinRZSonPO> list=DBAgent.find(sql, params);
		return list;
	}

	@Override
	public void updateZiJinRZPOData(ZiJinRZPO po) {
		DBAgent.saveOrUpdate(po);
	}

//	@Override
//	public List<ZiJinRZBankPO> findZiJinRZBankPO(Long formrecordId) {
//		Map<String,Object> params=new HashMap<String,Object>();
//		String sql=" from ZiJinRZBankPO where formmain_id=:formrecordId";
//		params.put("formrecordId", formrecordId);
//		List<ZiJinRZBankPO> list=DBAgent.find(sql, params);
//		return list;
//	}
//
//	@Override
//	public ZiJinRZBankPO findZiJinRZBankPOById(String pzh) {
//		Map<String,Object> params=new HashMap<String,Object>();
//		String sql=" from ZiJinRZBankPO where pzh=:pzh";
//		params.put("pzh", pzh);
//		List<ZiJinRZBankPO> list=DBAgent.find(sql, params);
//		return list.get(0);
//	}
//
//	@Override
//	public void updateZiJinRZBankPOData(ZiJinRZBankPO po) {
//		DBAgent.saveOrUpdate(po);
//	}

	@Override
	public NeibuZjPO findNeibuZjPOById(Long id) {
		Map<String, Object> params=new HashMap<String, Object>();
		String sql=" from NeibuZjPO where ID=:id";
		params.put("id", id);
		List<NeibuZjPO> list=DBAgent.find(sql,params);
		if (list!=null&&list.size()>0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public List<NeibuZjSonPO> findNeibuZjSonPO(Long formrecordId) {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql=" from NeibuZjSonPO where formmain_id=:formrecordId";
		params.put("formrecordId", formrecordId);
		List<NeibuZjSonPO> list=DBAgent.find(sql, params);
		return list;
	}
	

	@Override
	public List<NeibuZjPJPO> findNeibuZjPJPO(Long formrecordId) {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql=" from NeibuZjPJPO where formmain_id=:formrecordId";
		params.put("formrecordId", formrecordId);
		List<NeibuZjPJPO> list=DBAgent.find(sql, params);
		return list;
	}

	@Override
	public List<NeibuZjBankPO> findNeibuZjBankPO(Long formrecordId) {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql=" from NeibuZjBankPO where formmain_id=:formrecordId";
		params.put("formrecordId", formrecordId);
		List<NeibuZjBankPO> list=DBAgent.find(sql, params);
		return list;
	}

	@Override
	public NeibuZjBankPO findNeibuZjBankPOById(String pzh) {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql=" from NeibuZjBankPO where field0197=:pzh";
		params.put("pzh", pzh);
		List<NeibuZjBankPO> list=DBAgent.find(sql, params);
		if (list!=null&&list.size()>0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public void updateNeibuZjBankPOData(NeibuZjBankPO po) {
		DBAgent.saveOrUpdate(po);
	}

	@Override
	public HetongPO findHetongPOById(Long id) {
		Map<String, Object> params=new HashMap<String, Object>();
		String sql=" from HetongPO where ID=:id";
		params.put("id", id);
		List<HetongPO> list=DBAgent.find(sql,params);
		if (list!=null&&list.size()>0) {
			return list.get(0);
		}
		return null;
	}
	
	@Override
	public List<HetongPJPO> findHetongPJPO(Long formrecordId) {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql=" from HetongPJPO where formmain_id=:formrecordId";
		params.put("formrecordId", formrecordId);
		List<HetongPJPO> list=DBAgent.find(sql, params);
		return list;
	}

	@Override
	public List<HetongSonPO> findHetongSonPO(Long formrecordId) {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql=" from HetongSonPO where formmain_id=:formrecordId";
		params.put("formrecordId", formrecordId);
		List<HetongSonPO> list=DBAgent.find(sql, params);
		return list;
	}

	@Override
	public List<HetongBankPO> findHetongBankPO(Long formrecordId) {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql=" from HetongBankPO where formmain_id=:formrecordId";
		params.put("formrecordId", formrecordId);
		List<HetongBankPO> list=DBAgent.find(sql, params);
		return list;
	}

	@Override
	public HetongBankPO findHetongBankPOById(String pzh) {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql=" from HetongBankPO where field0197=:pzh";
		params.put("pzh", pzh);
		List<HetongBankPO> list=DBAgent.find(sql, params);
		if (list!=null&&list.size()>0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public void updateHetongBankPOData(HetongBankPO po) {
		DBAgent.saveOrUpdate(po);
	}

	@Override
	public ChailfPO findChailfPOById(Long id) {
		Map<String, Object> params=new HashMap<String, Object>();
		String sql=" from ChailfPO where ID=:id";
		params.put("id", id);
		List<ChailfPO> list=DBAgent.find(sql,params);
		if (list!=null&&list.size()>0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public List<ChailfPJPO> findChailfPJPO(Long formrecordId) {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql=" from ChailfPJPO where formmain_id=:formrecordId";
		params.put("formrecordId", formrecordId);
		List<ChailfPJPO> list=DBAgent.find(sql, params);
		return list;
	}
	
	@Override
	public List<ChailfSonPO> findChailfSonPO(Long formrecordId) {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql=" from ChailfSonPO where formmain_id=:formrecordId";
		params.put("formrecordId", formrecordId);
		List<ChailfSonPO> list=DBAgent.find(sql, params);
		return list;
	}

	@Override
	public List<ChailfBankPO> findChailfBankPO(Long formrecordId) {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql=" from ChailfBankPO where formmain_id=:formrecordId";
		params.put("formrecordId", formrecordId);
		List<ChailfBankPO> list=DBAgent.find(sql, params);
		return list;
	}

	@Override
	public ChailfBankPO findChailfBankPOById(String pzh) {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql=" from ChailfBankPO where field0200=:pzh";
		params.put("pzh", pzh);
		List<ChailfBankPO> list=DBAgent.find(sql, params);
		if (list!=null&&list.size()>0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public void updateChailfBankPOData(ChailfBankPO po) {
		DBAgent.saveOrUpdate(po);
	}

	@Override
	public List<OrgPrincipal> getPrincipaByMemberId(long memberId) {
		Map<String, Object> params = new HashMap<>();
	    params.put("memberId", Long.valueOf(memberId));
	    String sql = "from OrgPrincipal where memberId =:memberId";
	    List<OrgPrincipal> results = DBAgent.find(sql, params);
	    return results;
	}

	@Override
	public FapiaoRzPO findFapiaoRzPOById(Long id) {
		Map<String, Object> params=new HashMap<String, Object>();
		String sql=" from FapiaoRzPO where ID=:id";
		params.put("id", id);
		List<FapiaoRzPO> list=DBAgent.find(sql,params);
		if (list!=null&&list.size()>0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public List<FapiaoRzPJPO> findFapiaoRzPJPO(Long formrecordId) {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql=" from FapiaoRzPJPO where formmain_id=:formrecordId";
		params.put("formrecordId", formrecordId);
		List<FapiaoRzPJPO> list=DBAgent.find(sql, params);
		return list;
	}

	@Override
	public void updateFapiaoRzPOData(FapiaoRzPO po) {
		DBAgent.saveOrUpdate(po);
	}

	@Override
	public FapiaoKjPO findFapiaoKjPOById(Long id) {
		Map<String, Object> params=new HashMap<String, Object>();
		String sql=" from FapiaoKjPO where ID=:id";
		params.put("id", id);
		List<FapiaoKjPO> list=DBAgent.find(sql,params);
		if (list!=null&&list.size()>0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public List<FapiaoKjPJPO> findFapiaoKjPJPO(Long formrecordId) {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql=" from FapiaoKjPJPO where formmain_id=:formrecordId";
		params.put("formrecordId", formrecordId);
		List<FapiaoKjPJPO> list=DBAgent.find(sql, params);
		return list;
	}

	@Override
	public List<FapiaoKjBankPO> findFapiaoKjBankPO(Long formrecordId) {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql=" from FapiaoKjBankPO where formmain_id=:formrecordId";
		params.put("formrecordId", formrecordId);
		List<FapiaoKjBankPO> list=DBAgent.find(sql, params);
		return list;
	}

	@Override
	public FapiaoKjBankPO findFapiaoKjBankPOById(String pzh) {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql=" from FapiaoKjBankPO where field0197=:pzh";
		params.put("pzh", pzh);
		List<FapiaoKjBankPO> list=DBAgent.find(sql, params);
		if (list!=null&&list.size()>0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public void updateFapiaoKjBankPOData(FapiaoKjBankPO po) {
		DBAgent.saveOrUpdate(po);
	}

	@Override
	public HuiKuanPO findHuiKuanPOById(Long id) {
		Map<String, Object> params=new HashMap<String, Object>();
		String sql=" from HuiKuanPO where ID=:id";
		params.put("id", id);
		List<HuiKuanPO> list=DBAgent.find(sql,params);
		if (list!=null&&list.size()>0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public List<HuiKuanSonPO> findHuiKuanSonPO(Long formrecordId) {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql=" from HuiKuanSonPO where formmain_id=:formrecordId";
		params.put("formrecordId", formrecordId);
		List<HuiKuanSonPO> list=DBAgent.find(sql, params);
		return list;
	}
	

	@Override
	public List<HuiKuanPJPO> findHuiKuanPJPO(Long formrecordId) {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql=" from HuiKuanPJPO where formmain_id=:formrecordId";
		params.put("formrecordId", formrecordId);
		List<HuiKuanPJPO> list=DBAgent.find(sql, params);
		return list;
	}

	@Override
	public List<HuiKuanBankPO> findHuiKuanBankPO(Long formrecordId) {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql=" from HuiKuanBankPO where formmain_id=:formrecordId";
		params.put("formrecordId", formrecordId);
		List<HuiKuanBankPO> list=DBAgent.find(sql, params);
		return list;
	}

	@Override
	public HuiKuanBankPO findHuiKuanBankPOById(String pzh) {
		Map<String,Object> params=new HashMap<String,Object>();
		String sql=" from HuiKuanBankPO where field0197=:pzh";
		params.put("pzh", pzh);
		List<HuiKuanBankPO> list=DBAgent.find(sql, params);
		if (list!=null&&list.size()>0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public void updateHuiKuanBankPOData(HuiKuanBankPO po) {
		DBAgent.saveOrUpdate(po);
	}

}
